#include <header.h>


void getFileName(char *path, int index){

    DIR *dir = opendir(path);

    struct dirent * dt = readdir(dir);
    while(dt != NULL){
        if(dt->d_type == DT_DIR && dt->d_name[0] != '.'){
            for(int i=0; i<index*4; i++){
                printf(" ");
            }
            printf("%s \n", dt->d_name);
            // 遍历子目录
            char buf[500] = {0};
            sprintf(buf, "%s/%s", path, dt->d_name);
            getFileName(buf, index+1);
        }else{
            for(int i=0; i<index*4; i++){
                printf(" ");
            }
            printf("%s \n", dt->d_name);
        }

        dt = readdir(dir);
    }

    closedir(dir);
}

int main(){

    //char *path = "/home/snow/3th/04_Linux/CODE/Day15/dir1";
    char *path = "./dir1";

    getFileName(path, 1);


    return 0;
}

